package com.xiaode.controller.app.task.exercise;

import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import com.jfinal.ext.cors.EnableCORS;
import com.jfinal.kit.Ret;
import com.xiaode.util.apidoc.annotation.Api;
import com.xiaode.util.apidoc.annotation.ApiOper;
import com.xiaode.util.apidoc.annotation.ApiPara;
import java.util.Date;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;

@Path("/exercise")
@Api("锻炼任务模块")
@EnableCORS
public class ExerciseController extends Controller {
	
    @Inject
    ExerciseService service;


    @ApiOper("锻炼打卡")
    public void exerciseClock(@NotBlank @ApiPara(value = "date", notes = "打卡日期") Date date) throws Exception {
    	Integer accountId = getAttr("accountId");
    	Integer userId = getAttr("userId");
        Ret ret = service.exerciseClock(accountId, userId, date);
        renderJson(ret);
    }

    @ApiOper("更新打卡")
    public void updateExercise(
    		@Size @ApiPara(value = "exerciseId", notes = "打卡记录Id") Integer exerciseId,
    		@ApiPara(value = "sports", notes = "运动类型") String sports,
    		@ApiPara(value = "content", notes = "内容") String content) throws Exception {
    	Integer accountId = getAttr("accountId");
        Ret ret = service.updateExercise(accountId, exerciseId, sports, content);
        renderJson(ret);
    }

    @ApiOper("查询打卡记录")
    public void findExercise(
    		@ApiPara(value = "accountId", notes = "账号id（不传代表查询自己的）") Integer accountId,
    		@NotBlank @ApiPara(value = "date", notes = "打卡日期") Date date) throws Exception {
    	Integer accountIdMy = getAttr("accountId");
        Ret ret = service.findExercise(accountId, accountIdMy, date);
        renderJson(ret);
    }
    
    
    

}
